@extends('layouts.default')

@section('title')
@parent
{{ $title }}
@stop


@section('right')

<script type="text/javascript" charset="utf-8" src="{{ asset('assets/ueditor/ueditor.config.js') }}"></script>
<script type="text/javascript" charset="utf-8" src="{{ asset('assets/ueditor/ueditor.all.min.js') }}"></script>
<script type="text/javascript" charset="utf-8" src="{{ asset('assets/ueditor/lang/zh-cn/zh-cn.js') }}"></script>
<script type="text/javascript" charset="utf-8" src="{{ asset('assets/AjaxFileUploader/ajaxfileupload.js') }}"></script>
<link rel="stylesheet" href="{{ asset('assets/css/appmsg_edit1f5d9c.css') }}"  />
<link rel="stylesheet" href="{{ asset('assets/css/base209e63.css') }}"  />
<link rel="stylesheet" href="{{ asset('assets/css/appmsg_editor1f18a0.css') }}"  />
           <ol class="breadcrumb">
              <li><a href="login-index.html">首页</a></li>
              <li><a href="{{ route('materials.index') }}">素材管理</a></li>
              <li class="active">{{ $title }}</li>
            </ol>

            <div class="main_bd">
                {{ Form::open(array('url' => 'materials/update', 'enctype' => 'multipart/form-data')) }}
                {{ Form::hidden('picname',$material->image,array('id'=>'picname')) }}
                {{ Form::hidden('pid',$push->id) }}
                {{ Form::hidden('push_type','1') }}
            	<div class="media_preview_area">
                    <div class="appmsg  editing">
                        <div id="js_appmsg_preview" class="appmsg_content">
                            <div id="appmsgItem1" data-fileid="" data-id="1" class="js_appmsg_item ">
                                <h4 class="appmsg_title"><a onclick="return false;" href="javascript:void(0);" target="_blank">标题</a></h4>
                                <div class="appmsg_info">
                                    <em class="appmsg_date"></em>
                                </div>
                                <div class="appmsg_thumb_wrp">
                                    <img style="width: 290px;height: 160px" class="" id="thumb_cover" src="{{ $material->image }}">
                                </div>
                                <p class="appmsg_desc"></p>
                            </div>
                        </div>
                    </div>
                    <div class="Dan-select">
                        <label>分组</label>
                        {{ Form::select('type', array('市场活动' => '市场活动', '培训信息' => '培训信息', '常见技术问题' => '常见技术问题', '其他问题' => '其他问题')); }}
                    </div>
                </div>
                <div class="media_edit_area">
                    <div class="js_appmsg_editor">
                        <div class="appmsg_editor" style="margin-top:0px;">
                            <div class="inner">
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">标题</label>
                                    <span class="frm_input_box">
                                    {{--<input type="text" class="frm_input js_title">--}}
                                    {{ Form::text('title',$material->title ,array('class' => 'frm_input js_title')); }}
                                    </span>
                                </div>
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">
                                        <strong class="title">作者</strong>
                                        <p class="tips l">（选填）</p>
                                    </label>
                                    <span class="frm_input_box">
                                    {{ Form::text('author',$material->author ,array('class' => 'frm_input js_')); }}</span>
                                </div>
                                <div class="appmsg_edit_item">
                                    <label for="" class="frm_label">
                                        <strong class="title">封面</strong>
                                        <p class="js_cover_tip tips">（大图片建议尺寸：900像素 * 500像素）</p>
                                    </label>
                                    <div class="upload_wrap">
                                        <div class="upload_box">
                                            <div class="upload_area">
                                             </div>
                                        </div>&nbsp;
                                        <p class="js_cover upload_preview" style="display: none;">
                                            <a class="js_removeCover" href="javascript:void(0);" onclick="return false;">删除</a>
                                        </p>
                                    </div>
                                    <div class="frm_tips">
                                            @if($errors->has())
                                            @foreach($errors->all() as $error)
                                            <div data-alert class="alert-box warning round">
                                                {{$error}}
                                                <a href="#" class="close">&times;</a>
                                            </div>
                                            @endforeach
                                            @endif
                                         <p><input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input">

                        				 <button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">上传</button>
		<img id="loading" src="{{ asset('assets/AjaxFileUploader/loading.gif') }}" style="display:none;"></p>
                        				 <p>{{ Form::checkbox('show_cover_pic', '1', false) }}
                        				 <span>封面图片显示在正文中</span></p>
                                    </div>
                                </div>

                                <div class="js_desc_area dn appmsg_edit_item">
                                    <label for="" class="frm_label">摘要 (不能超过120个字)</label>
                                    <span class="frm_textarea_box">
                                    {{ Form::textarea('summary', $material->summary,array('class' => 'js_desc frm_textarea')); }}</span>
                                </div>
                                <div class="js_desc_area dn appmsg_edit_item">
                                    <label for="" class="frm_label">正文 *(正文和链接地址至少填写一项)</label>
                                        <script id="editor" type="text/plain" style="width:370px;height:200px;">{{ $material->content }}</script>
                                </div>
                                <div id="js_ueditor" class="appmsg_edit_item content_edit">

                                </div>
                                <p><a class="js_addURL" href="javascript:void(0);" onclick="add_url();">添加原文链接</a></p>
                                <div id="hd_url" class="js_url_area dn appmsg_edit_item" @if($material->link  == '') style="display: none;" @endif>
                                    <label for="" class="frm_label">原文链接</label>
                                    <span class="frm_input_box">
                                    {{ Form::text('link',$material->link ,array('class' => 'js_url frm_input')); }}
                                    </span>
                                </div>
                    		</div>
                            <i class="arrow arrow_out" style="margin-top: 0px;"></i>
                            <i class="arrow arrow_in" style="margin-top: 0px;"></i>
                        </div>
                    </div>
                </div>
                <div class="tool_area">
                    <div class="tool_bar border tc">
                        <span id="js_submit" class="btn btn_input btn_primary2">{{ Form::submit('保存'); }}</span>
                        <span id="js_preview" class="btn btn_input btn_default"><button>cancel</button></span>
                    </div>
               </div>
            {{ Form::close() }}
            </div>
            <script type="text/javascript">

                  //实例化编辑器
                  //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
                var ue = UE.getEditor('editor');
                function add_url(){
                    $('#hd_url').toggle();
                }

            </script>
            <script type="text/javascript">
            function ajaxFileUpload()
            {
                $("#loading")
                .ajaxStart(function(){
                    $(this).show();
                })
                .ajaxComplete(function(){
                    $(this).hide();
                });

                $.ajaxFileUpload
                (
                    {
                        url:'{{ route('materials.ajaxpic') }}',
                        secureuri:false,
                        fileElementId:'fileToUpload',
                        dataType: 'json',
                        data:{name:'logan', id:'id'},
                        success: function (data, status)
                        {
                            if(typeof(data.error) != 'undefined')
                            {
                                if(data.error != 'ok')
                                {
                                    alert(data.error);
                                }else
                                {
                                    var src ='/uploads/materials/images/'+data.pic_name;
                                    $('#thumb_cover').attr('src',src);
                                    $('#picname').val(src);
                                }
                            }
                        },
                        error: function (data, status, e)
                        {
                            alert(e);
                        }
                    }
                )

                return false;

            }
        </script>
@stop